package worldCount;

import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.Map;

public class Write {
	public void writeout(int countChar,int countword,int countline,Map<String, Integer> map,int x,String out,Map<String, Integer> map1,int len) throws IOException
	{
		File file =new File(out);
		FileWriter fw =new FileWriter(file,true);
		PrintWriter pw = new PrintWriter(fw);
		pw.println("characters:"+countChar);
		pw.println("words:"+countword);
		pw.println("lines:"+countline);
		pw.flush();
		if(x!=0)
		{

			Sort sort = new Sort();
			int x1=0;
			for(Map.Entry<String,Integer> entry:sort.sortout(map))
			{
				if(x1<x)
				{
					pw.println("<"+entry.getKey()+">:"+entry.getValue());
					pw.flush();
					x1++;
				}
			}
		}
		if(len!=0)
		{
			Sort sort = new Sort();
			int x1 = 0;
			for(Map.Entry<String,Integer> entry:sort.sortout(map1))
			{
				if(x1<10)
				{
					pw.println("<"+entry.getKey()+">:"+entry.getValue());
					pw.flush();
					x1++;
				}
			}
		}
	}
}
